﻿using System;
using System.Net.Http;

namespace iTeamyou.LTS.Core.Services
{
	public class EKPFlowService
	{
        public SharedService _sharedService = new SharedService();
        public HttpClient _httpClient;

        public EKPFlowService()
		{
            _httpClient = new HttpClient()
            {
                BaseAddress = new Uri(_sharedService.GetConfig("EKPRestBaseURL"))
            };
        }

        public string AddReview(string templateId, string docSubject, string userId, string formValue = null)
        {
            var formData = new MultipartFormDataContent
            {
                { new StringContent(docSubject), "docSubject" },
                //{ new StringContent(_sharedService.GetConfig("EKPLicenseTemplateId")), "fdTemplateId" },
                { new StringContent(templateId), "fdTemplateId" },
                { new StringContent("{\"LoginName\":\""+userId+"\"}"), "docCreator" }
            };

            if (!string.IsNullOrEmpty(formValue))
                formData.Add(new StringContent(formValue), "formValues");

            var response = _httpClient.PostAsync(_sharedService.GetConfig("EKPRestReviewPath"), formData).Result;
            var fdInstanceId = response.Content.ReadAsStringAsync().Result;

            return fdInstanceId;
        }
	}
}

